// --------------------------------------------------------------------------------------------------------------------
// <copyright file="GamePadAgentMessage.cs" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace Microsoft.Robotics.Interaction.Runtime.Input
{
    using System.Runtime.Serialization;
    using Microsoft.Robotics.Runtime;

    /// <summary>
    /// Message type for GamePadAgent
    /// </summary>
    [DataContract]
    public class GamePadAgentMessage : AgentMessage
    {
        /// <summary>
        /// Initializes a new instance of the GamePadAgentMessage class.
        /// </summary>
        public GamePadAgentMessage()
            : base(AgentMessage.GetCurrentTime())
        {
        }

        /// <summary>
        /// Initializes a new instance of the GamePadAgentMessage class
        /// </summary>
        /// <param name="buttons">Game pad buttons state</param>
        /// <param name="dPad">Game pad dpad state</param>
        /// <param name="thumbSticks">Game pad thumb sticks state</param>
        /// <param name="triggers">Game pad triggers state</param>
        public GamePadAgentMessage(GamePadAgentButtons buttons, GamePadAgentDPad dPad, GamePadAgentThumbSticks thumbSticks, GamePadAgentTriggers triggers)
            : base(AgentMessage.GetCurrentTime())
        {
            this.Buttons = buttons;
            this.DPad = dPad;
            this.ThumbSticks = thumbSticks;
            this.Triggers = triggers;
        }

        /// <summary>
        /// Gets or sets the Buttons state for the GamePad
        /// </summary>
        [DataMember]
        public GamePadAgentButtons Buttons { get; set; }

        /// <summary>
        /// Gets or sets the DPad state for the GamePad
        /// </summary>
        [DataMember]
        public GamePadAgentDPad DPad { get; set; }

        /// <summary>
        /// Gets or sets the ThumbStick state for the GamePad
        /// </summary>
        [DataMember]
        public GamePadAgentThumbSticks ThumbSticks { get; set; }

        /// <summary>
        /// Gets or sets the Trigger state for the GamePad
        /// </summary>
        [DataMember]
        public GamePadAgentTriggers Triggers { get; set; }

        /// <summary>
        /// Serializable class for XNA Vector2
        /// </summary>
        [DataContract]
        public class GamePadAgentVector2
        {
            /// <summary>
            /// Gets or sets X
            /// </summary>
            [DataMember]
            public float X { get; set; }

            /// <summary>
            /// Gets or sets Y
            /// </summary>
            [DataMember]
            public float Y { get; set; }

            /// <summary>
            /// Pretty Print
            /// </summary>
            /// <returns>Pretty print string</returns>
            public override string ToString()
            {
                return string.Format("{0}, {1}", this.X, this.Y);
            }
        }

        /// <summary>
        /// Serializable class for XNA GamePadThumbSticks
        /// </summary>
        [DataContract]
        public class GamePadAgentThumbSticks
        {
            /// <summary>
            /// Initializes a new instance of the <see cref="GamePadAgentThumbSticks" /> class.
            /// </summary>
            public GamePadAgentThumbSticks()
            {
                this.Left = new GamePadAgentVector2();
                this.Right = new GamePadAgentVector2();
            }        
            
            /// <summary>
            /// Gets or sets Left ThumbStick
            /// </summary>
            [DataMember]
            public GamePadAgentVector2 Left { get; set; }

            /// <summary>
            /// Gets or sets Right ThumbStick
            /// </summary>
            [DataMember]
            public GamePadAgentVector2 Right { get; set; }
        }

        /// <summary>
        /// Serializable class for XNA GamePadTriggers
        /// </summary>
        [DataContract]
        public class GamePadAgentTriggers
        {
            /// <summary>
            /// Gets or sets Left Trigger
            /// </summary>
            [DataMember]
            public float Left { get; set; }

            /// <summary>
            /// Gets or sets Right Trigger
            /// </summary>
            [DataMember]
            public float Right { get; set; }
        }

        /// <summary>
        /// Serializable class for XNA GamePadButtons
        /// </summary>
        [DataContract]
        public class GamePadAgentButtons
        {
            /// <summary>
            /// Gets or sets a value indicating whether A Button is pressed
            /// </summary>
            [DataMember]
            public bool A { get; set; }

            /// <summary>
            /// Gets or sets a value indicating whether B Button is pressed
            /// </summary>
            [DataMember]
            public bool B { get; set; }

            /// <summary>
            /// Gets or sets a value indicating whether Back Button is pressed
            /// </summary>
            [DataMember]
            public bool Back { get; set; }

            /// <summary>
            /// Gets or sets a value indicating whether Big Button is pressed
            /// </summary>
            [DataMember]
            public bool BigButton { get; set; }

            /// <summary>
            /// Gets or sets a value indicating whether Left Shoulder Button is pressed
            /// </summary>
            [DataMember]
            public bool LeftShoulder { get; set; }

            /// <summary>
            /// Gets or sets a value indicating whether Left Stick Button is pressed
            /// </summary>
            [DataMember]
            public bool LeftStick { get; set; }

            /// <summary>
            /// Gets or sets a value indicating whether Right Shoulder Button is pressed
            /// </summary>
            [DataMember]
            public bool RightShoulder { get; set; }

            /// <summary>
            /// Gets or sets a value indicating whether Right Stick Button is pressed
            /// </summary>
            [DataMember]
            public bool RightStick { get; set; }

            /// <summary>
            /// Gets or sets a value indicating whether Start Button is pressed
            /// </summary>
            [DataMember]
            public bool Start { get; set; }

            /// <summary>
            /// Gets or sets a value indicating whether X Button is pressed
            /// </summary>
            [DataMember]
            public bool X { get; set; }

            /// <summary>
            /// Gets or sets a value indicating whether Y Button is pressed
            /// </summary>
            [DataMember]
            public bool Y { get; set; }
        }

        /// <summary>
        /// Serializable class for XNA GamePadDPad
        /// </summary>
        [DataContract]
        public class GamePadAgentDPad
        {
            /// <summary>
            /// Gets or sets a value indicating whether Up Button is pressed
            /// </summary>
            [DataMember]
            public bool Up { get; set; }

            /// <summary>
            /// Gets or sets a value indicating whether Down Button is pressed
            /// </summary>
            [DataMember]
            public bool Down { get; set; }

            /// <summary>
            /// Gets or sets a value indicating whether Left Button is pressed
            /// </summary>
            [DataMember]
            public bool Left { get; set; }

            /// <summary>
            /// Gets or sets a value indicating whether Right Button is pressed
            /// </summary>
            [DataMember]
            public bool Right { get; set; }
        }
    }
}
